package org.example.rubbish.service.impl;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.example.rubbish.entity.Site;
import org.example.rubbish.mapper.StationMapper;
import org.example.rubbish.service.StationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class StationServiceImpl extends ServiceImpl<StationMapper, Site> implements StationService {

    @Autowired
    private StationMapper stationMapper;

    @Override
    public Map<String, Object> getStationStats(Date startTime, Date endTime) {
        return stationMapper.selectStationStatistics(startTime, endTime);
    }

    @Override
    public boolean updateStationStatus(Long stationId, String status) {
        try {
            Site station = new Site();
            station.setId(stationId);
            station.setStatus(status);
            return this.updateById(station);
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public List<Site> getStationsForMap() {
        QueryWrapper<Site> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id", "name", "latitude", "longitude", "status", "location")
                .isNotNull("latitude")
                .isNotNull("longitude");
        return this.list(queryWrapper);
    }
}